﻿#pragma once
//实体类方法
#define IMETHODS(pobj,obj)\
typedef pobj PObj;\
typedef obj IObj;\
/*动态获取类型信息*/\
virtual PType GetType()const{ return PType::Make<pobj>(); }\
/*operator&重载*/\
IObj*operator&() { if (Object::RefCount<0)++Object::RefCount; return this; }\
IObj const*operator&()const { if (Object::RefCount<0)++Object::RefCount; return this; }\
virtual void SwapWith(Object&){Throw<PNotSupportException>();}

#define BMETHODS(pobj,obj)\
typedef pobj PObj;\
typedef obj IObj;\
/*动态获取类型信息*/\
virtual PType GetType()const{ return PType::Make<pobj>(); }\
/*operator&重载*/\
IObj*operator&() { if (Object::RefCount<0)++Object::RefCount; return this; }\
IObj const*operator&()const { if (Object::RefCount<0)++Object::RefCount; return this; }\
virtual void SwapWith(Object&o){SwapWith(*CastPointer<IObj>(&o));}\
template<class TT>void SwapWith(TT&o){Object::Swap(*this,o);}


//代理类方法
#define PIMETHODS_NODEFCTOR(pobj,obj)\
typedef pobj PObj;\
typedef obj IObj;\
/**@brief 复制构造函数*/\
inline pobj(pobj const&t){PObject::SetTo(t.PObject::GetPtr()); }\
/**@brief 从对象指针构造*/\
inline pobj(obj const* p){PObject::SetTo(StaticCastPointer(p)); }\
/**@brief 赋值*/\
inline pobj& operator=(pobj const&r) { PObject::SetTo(r.PObject::GetPtr()); return *this; }\
/**@brief 获取对象指针，并在对象指针为空时抛出异常*/\
inline obj* Ptr()const { return CheckPointer<obj>(PObject::GetPtr()); }\
/**@brief 获取对象指针*/\
inline obj* GetPtr()const {return CastPointer<obj>(PObject::GetPtr());}\
/**@brief 重载operator->*/\
inline obj* operator->()const { return Ptr(); }\
/**@brief 检查对象引用计数如果不为1，则进行Clone。空引用将抛出异常*/\
inline obj* OnePtr() { if ((index_t)PObject::RefCount != 1) { PObject::SetTo(((PCloneables*)this)->Ptr()->Clone()); } return CastPointer<obj>(PObject::GetPtr()); }\
/**@brief 获取对象类型*/\
inline PType GetType()const{return PObject::GetType();}


#define PIMETHODS(pobj,obj)\
PIMETHODS_NODEFCTOR(pobj,obj)\
/**@brief 默认构造函数*/\
inline pobj(){}

#define PMETHODS_NODEFCTOR(pobj,obj)\
PIMETHODS_NODEFCTOR(pobj,obj)

#define PMETHODS(pobj,obj)\
PIMETHODS_NODEFCTOR(pobj,obj)\
/**@brief 默认构造函数*/\
inline pobj(){}
